package net.message;

import net.message.processor.IMessageProcessor;
import net.Client;
import net.Util;

import java.awt.*;

public class NewLineMessage implements Message{

    public final int x;
    public final int y;
    public final int dx;
    public final int dy;
    public final Color color;
    public final int imageID;

    public NewLineMessage(int x, int y, int dx, int dy, Color color, int imageID) {
        this.x = x;
        this.y = y;
        this.dx = dx;
        this.dy = dy;
        this.color = color;
        this.imageID = imageID;
    }

    public NewLineMessage(byte[] source) {
        x = Util.byteArrayToInt(source, 0);
        y = Util.byteArrayToInt(source, 4);
        dx = Util.byteArrayToInt(source, 8);
        dy = Util.byteArrayToInt(source, 12);
        color = new Color(Util.byteArrayToInt(source, 16));
        imageID = Util.byteArrayToInt(source, 20);
    }

    @Override
    public void accept(IMessageProcessor processor, Client client) {
        processor.process(this, client);
    }

    @Override
    public byte[] toByteArray() {
        byte[] res = new byte[6 * 4];
        Util.intToByteArray(x, res, 0);
        Util.intToByteArray(y, res, 4);
        Util.intToByteArray(dx, res, 8);
        Util.intToByteArray(dy, res, 12);
        Util.intToByteArray(color.getRGB(), res, 16);
        Util.intToByteArray(imageID, res, 20);                                                
        return res;
    }

    @Override
    public MessageType getType(){
        return MessageType.NEW_LINE;
    }    
}
